package com.jt.provider.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.time.LocalTime;

public class TimeInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request,
                             HttpServletResponse response,
                             Object handler) throws Exception {
        System.out.println("==拦截==");
        LocalTime now = LocalTime.now();
        int hour = now.getHour();
        int f = now.getMinute();
        int m = now.getSecond();
        System.out.println("hour="+hour+":"+f+":"+m);
        if (hour<6||hour>23){
            throw new RuntimeException("请在允许时间内访问:6~23");
        }
        return true;
    }
}
